package d.max.rwp;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;
import d.max.rwp.action.Action;
import d.max.rwp.action.NavigateViewAction;
import d.max.rwp.ui.ViewSwitcher;
import d.max.rwp.ui.component.FilelistView;
import d.max.rwp.ui.component.ImageViewCheckable;

/**
 * author: Maxim Dybarskiy
 * date:   Sep 3, 2011
 * time:   9:23:51 PM
 */
public class SettingsActivity extends Activity {

    public static final String SCREEN_CLOCK = "clock";
    public static final String SCREEN_FILES = "files";
    public static final String SCREEN_HELP = "help";
    
    ViewSwitcher switcher = new ViewSwitcher();
    
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        
        setContentView(R.layout.settings);
        
        // temporary view. delete this after view manager implementation
//        TextView tmp = (TextView) findViewById(R.id.test_view);
        FilelistView tmp = (FilelistView) findViewById(R.id.test_view);
        
        // register screen switchers
        registerScreenSwitcher(R.id.actionbar_clock,
                R.drawable.clock_checked,
                R.drawable.clock_simple,
                new NavigateViewAction(tmp, "here will be CLOCK view"));
        registerScreenSwitcher(R.id.actionbar_list,
                R.drawable.list_checked,
                R.drawable.list_simple,
                new NavigateViewAction(tmp, "here will be FILE LIST view"));
        registerScreenSwitcher(R.id.actionbar_help,
                R.drawable.help_checked,
                R.drawable.help_simple,
                new NavigateViewAction(tmp, "here will be HELP view"));
        
        // set active view
        String screen = getIntent().getStringExtra("screen");
        if (SCREEN_CLOCK.equals(screen)) {
            switcher.switchOn(findViewById(R.id.actionbar_clock));
        }
        if (SCREEN_FILES.equals(screen)) {
            switcher.switchOn(findViewById(R.id.actionbar_list));
        }
        if (SCREEN_HELP.equals(screen)) {
            switcher.switchOn(findViewById(R.id.actionbar_help));
        }
    }
    
    private void registerScreenSwitcher(int id, int checkedId, int uncheckedId, Action action) {
        View view = findViewById(id);
        if (view != null && view instanceof ImageViewCheckable) {
            ImageViewCheckable ivc = (ImageViewCheckable) view;
            ivc.setIconCheckedId(checkedId);
            ivc.setIconUncheckedId(uncheckedId);
            switcher.add(ivc, action);
        }
    }
}
